#ifndef RTE_KT1260A_ETH_LWIP_H
#define RTE_KT1260A_ETH_LWIP_H

#include <smodule.h>

#undef connect
#undef accept

#include "STM32Ethernet.h"

class ETH_LWIP : public smodule {
public:
    ETH_LWIP();

    const char *name() override { return "ETH_LWIP"; }

    int begin(uint32_t tick) override;

#ifdef __PLATFORMIO_BUILD_DEBUG__
    int dev_test(uint32_t tick) final;
#endif

    int diag(uint32_t tick) override;

    int run(uint32_t tick) override;

    // EthernetClass Ethernet;

    static void set_ip();

    void end();

    bool is_connected();

    int encode(pb_object *msg, pb_ostream_t *stream) override {
        msg->object.eth = data;
        msg->which_object = pb_object_eth_tag;
        return pb_encode(stream, pb_object_fields, msg);
    }

    int iter(pb_field_iter_t *pS) override {
        return pb_field_iter_begin(pS, pb_eth_info_fields, &data);
    }

    int type() override { return pb_object_eth_tag; }

    pb_eth_info data;
    PB_BYTES_ARRAY_T(6) mac;
};

extern struct netif gnetif;
#endif // RTE_KT1260A_ETH_LWIP_H
